package com.yq.homework.day24;


import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/24 19:12
 * <p>
 * 定义一个这样的一个words数组，数组中每个字符串的格式为“词性:单词”
 * String[] words =
 * {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat",
 * "noun:hand","noun:hair"};
 * 要求:
 * 根据单词性质动词verb全部存入verb.txt文件中
 * 根据单词性质名词noun全部存入noun.txt文件中
 */
public class Demo01 {
    public static void main(String[] args) throws IOException {
        String[] words = {"verb:eat", "verb:drink", "verb:sleep", "verb:play", "noun:rice", "noun:meat",
                "noun:hand", "noun:hair"};
        FileOutputStream out1 = new FileOutputStream("verb.txt");
        FileOutputStream out2 = new FileOutputStream("noun.txt");

        for (String word : words) {
            String[] s1 = word.split(":");
            if (s1[0].equals("verb")) {
                out1.write(word.getBytes());
                out1.write(System.lineSeparator().getBytes());
            }else{
                out2.write(word.getBytes());
                out2.write(System.lineSeparator().getBytes());
            }
        }
        out1.close();
        out2.close();
    }


}
